const {
  baseUrl,
  getRequest,
  postRequest
} = require("../../../../../utils/request.js")
const {
  mock_flag
} = require("../../../../../data/index.js")
Page({
  data: {
    //图片
    img: '',
  },
  onLoad(options) {
    //初始化数据
    this.setData({
      img: options.img
    })
    //获取用户id
    const userId = wx.getStorageSync('userId');
    this.setData({
      userId: userId,
    })
  },
  /**
   * 跳转
   */
  //拍摄界面
  to_camera() {
    wx.navigateTo({
      url: '/pages/user/desc/camera/take/take',
    })
  },
  //用户详情
  to_user_desc() {
    wx.navigateTo({
      url: '/pages/user/desc/desc',
    })
  },
  /**
   * 确定事件
   */
  onSure() {
    //修改图片操作
    if (!mock_flag) {
      this.http_user_updateUserImg(this.data.img)
    }
    //返回个人详情界面
    this.to_user_desc()
  },
  /**
   * 网络请求
   */
  //修改头像
  http_user_updateUserImg(userImg) {
    postRequest(baseUrl + "/front/user/updateUserImg", {
      userId: this.data.userId,
      UserImg: userImg
    }).then(res => {
      if (res.code == 200) {
        wx.showToast({
          title: '修改成功',
          icon: 'success',
          duration: 2000
        })
      }
    })
  },

})